from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"\text{设函数}$f\left( x\right) $\text{在}$x=0$\text{处三阶可导,则下列命题中所有不正确命题的序号为}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
        text1 = Tex(
                   r"\text{(1)若}$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{2}}=1$\text{,则}$\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}=2$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-5,0])
        text2 = Tex(
                    r"\text{(2)若}$\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}=2$\text{,则}$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{2}}=1$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,-5,0])
        text3 = Tex(
                   r"\text{(3)若}$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{3}}=1$\text{,则}$\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}=3$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-12,0])
        text4 = Tex(
                    r"\text{(4)若}$\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}=3$\text{,则}$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{3}}=1$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,-12,0])

        self.play(Write(text),self.camera.frame.animate.scale(0.8),Write(text1),Write(text2),Write(text3),Write(text4))
        self.wait(0.1)
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        self.play(text.animate().move_to([0,20,0]),text1.animate().move_to([-22,15,0]) ,text2.animate().move_to([22,15,0]),text3.animate().move_to([-22,8,0]),text4.animate().move_to([22,8,0])  )
        self.wait(0.1)
         #半透明矩阵扩展
        rectangle=Rectangle(color=YELLOW,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,15,0])
        self.play(
            rectangle.animate.stretch(45.0,dim=0)
        )
        self.wait(0.1)

        text5 = Tex(
                   r"$1=\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{2}}===\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-5,0])
        self.play(Create(text5))
        self.wait(0.1)
        text6 = Tex(
                   r"\text{洛}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-17.5,-1,0])
        self.play(Create(text6))
        self.wait(0.1)
        text7 = Tex(
                   r"\text{?}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).move_to([-17,-15,0])
        self.play(Create(text7))
        self.wait(0.1)
        self.play(FadeOut(text7))
        self.wait(0.1)


        text8 = Tex(
                   r"}$1.\dfrac{0}{0}$\text{型}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-15,0])
        text9 = Tex(
                    r"\text{2.去心领域可导} "
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-20,0])
        text10 = Tex(
                   r"\text{3.洛后极限三种情况：存在,∞,震荡}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-25,0])

        self.play(Create(text8),Create(text9),Create(text10))
        self.wait(0.1)

        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=45,height=11.5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([-22, -17, 0])
        self.play(Create(rectangle1))
        self.wait(0.1)

        text11 = Tex(
                   r"\text{存在性}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-17,0])
        self.play(Create(text11))
        self.wait(0.1)
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=45,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([-22, -25, 0])
        self.play(Create(rectangle2))
        self.wait(0.1)

        text12 = Tex(
                   r"\text{有用性}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-25,0])
        self.play(Create(text12))
        self.wait(0.1)

        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=16,height=7
                            ,stroke_color=RED,stroke_width=20)
        rectangle3.move_to([-29.5, -5, 0])
        self.play(Create(rectangle3))
        self.wait(0.1)

        #半透明矩阵扩展
        rectangle4=Rectangle(color=GREEN,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,-15,0])
        self.play(
            rectangle4.animate.stretch(45.0,dim=0)
        )
        self.wait(0.1)
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,20,0])
        self.play(
            rectangle5.animate.stretch(35.0,dim=0)
        )
        self.wait(0.1)
        self.play(FadeOut(rectangle5))
        self.wait(0.1)

        self.play(
            rectangle4.animate.move_to([-22,-20,0])
        )
        self.wait(0.1)
        text13 = Tex(
                   r"\text{?}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).move_to([5,-5,0])
        self.play(Create(text13),rectangle3.animate.stretch(0.8,dim=0).shift(21*RIGHT),rectangle4.animate.move_to([-22,-25,0]).set_color(RED))
        self.wait(0.1)
        
        
        self.play(FadeOut(text13),FadeOut(rectangle4))
        self.wait(0.1)

        rectangle6=Rectangle(color=GREEN,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,-15,0])
        self.play(
            rectangle6.animate.stretch(45.0,dim=0)
        )
        self.wait(0.1)





        #箭头
        #箭头引出
        arrow = Arrow(start=[6,2.5,0],end=[0,0,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        self.wait(0.1)

        self.play(
            rectangle6.animate.stretch(0.05,dim=0).move_to([-9,-25,0])
        )
        self.wait(0.1)
        
        #镜头拉近
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.5).move_to([-30,-5,0]))
        self.wait(0.1)
        #文本
        text14 = Tex(
                   r"$\infty $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([-45,-5,0])
        self.play(Create(text14),FadeOut(arrow))
        self.wait(0.1)
        self.play(Restore(self.camera.frame))
        self.wait(0.1)
        self.play(FadeOut(text14))
        self.wait(0.1)

        self.play(
            rectangle6.animate.stretch(20,dim=0).move_to([-22,-15,0])
        )
        self.wait(0.1)
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,20,0])
        self.play(
            rectangle7.animate.stretch(35.0,dim=0)
        )
        self.wait(0.1)
        self.play(FadeOut(rectangle7))
        self.wait(0.1)
        self.play(
            rectangle6.animate.move_to([-22,-20,0])
        )
        self.wait(0.1)
        #文本
        text15 = Tex(
                   r"$=\lim\limits _{x\rightarrow 0}\frac{f''\left( x\right) }{2} $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text5,RIGHT,buff=1)
        self.play(Create(text15))
        self.wait(0.1)
        self.play(
            rectangle3.animate.set_width(15).set_height(8).move_to([9,-5,0])
        )
        self.wait(0.1)


        #文本
        text16 = Tex(
                   r"$=\dfrac{f''\left( 0\right) }{2}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text15,RIGHT,buff=1)
        self.play(Create(text16))
        self.wait(0.1)
        self.play(
            rectangle3.animate.set_width(15).set_height(8).move_to([24,-5,0])
        )
        self.wait(0.1)

        text17 = Tex(
                   r"\text{存在}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text16,RIGHT,buff=1)
        self.play(Create(text17))
        self.wait(0.1)

        self.play(
            rectangle6.animate.stretch(0.1,dim=0).move_to([-14,-25,0]),FadeOut(rectangle3)
        )
        self.wait(0.1)
        #长框框

        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=70,height=10
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle7.move_to([-3, -5, 0])
        self.play(Create(rectangle7))

        self.wait(0.1)

        #淡出部分元素
        self.play(Uncreate(rectangle7),FadeOut(rectangle6),FadeOut(rectangle),Uncreate(text17)
                  ,Uncreate(text16),Uncreate(text15),Uncreate(text5)
                  ,Uncreate(text6))
        self.wait(0.1)    

        #序号2

        #半透明矩阵扩展
        rectangle8=Rectangle(color=YELLOW,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([22,15,0])
        self.play(
            rectangle8.animate.stretch(45.0,dim=0)
        )
       
        

        text18 = Tex(
                   r"$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x\right) }{x^{2}}===\lim\limits _{x\rightarrow 0}\dfrac{f'\left( x\right) }{x}=2$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-5,0])
        self.play(Create(text18))
        self.wait(0.1)
        text19 = Tex(
                   r"\text{洛}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22.5,-1,0])
        self.play(Create(text19))
        self.wait(0.1)

        rectangle12=Rectangle(color=BLUE,fill_opacity=0.0,width=17,height=6
                            ,stroke_color=RED,stroke_width=20)
        rectangle12.move_to([-10, -5, 0])
        self.play(Create(rectangle12))
        self.play(FadeOut(rectangle12))

        #镜头拉近

        self.play(self.camera.frame.animate.scale(0.8).move_to([-12.5,-25,0]))

        #框框闪动

        rectangle9=Rectangle(color=BLUE,fill_opacity=0.0,width=5,height=5
                            ,stroke_color=RED,stroke_width=20)
        rectangle9.move_to([-14, -25, 0])
        self.play(Create(rectangle9))
        self.play(FadeOut(rectangle9))

        #镜头转移

        self.play(self.camera.frame.animate.move_to([-40,-5,0]))
        #文本
        text20 = Tex(
                   r"\text{2}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([-45,-5,0])
        self.play(Create(text20))
        self.play(FadeOut(text20))
        #镜头拉回
        self.play(Restore(self.camera.frame))

        #半透明框框扩展

        rectangle11=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,20,0])
        self.play(
            rectangle11.animate.stretch(35.0,dim=0)
        )
        self.wait(0.1)
        self.play(FadeOut(rectangle11))
        self.wait(0.1)

        rectangle10=Rectangle(color=GREEN,fill_opacity=0.5,width=1,height=5
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,-20,0])
        self.play(
            rectangle10.animate.stretch(45.0,dim=0)
        )
        self.wait(0.1)
        #半透明框框移动，并设置颜色为红色
        self.play(
            rectangle10.animate.move_to([-22,-15,0]).set_color(RED)
        )

        #半透明框框淡出
        self.play(FadeOut(rectangle8),FadeOut(rectangle10))

        #半透明矩阵扩展
        rectangle15=Rectangle(color=YELLOW,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,8,0])
       
        #半透明矩阵扩展
        rectangle16=Rectangle(color=YELLOW,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([22,8,0])
        self.play(
            rectangle15.animate.stretch(45.0,dim=0),
            rectangle16.animate.stretch(45.0,dim=0)
        )
        






        self.wait()